<html>
<head>
<title>Catalog Online Colegiul Tehnic ,,Mihai Viteazu'' Vulcan</title>
<br><br>
<center>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<body background="img/bg.jpg"> 
	<font face="Berlin Sans FB Demi" color="#357EC7" size="3">
<br><br>
<table border="1">
<form method="post" action="passwd.php">
<tr><td><font face="Berlin Sans FB Demi" color="#357EC7" size="2">Adresa de email:</td><td></font><input type="text" name="email"></td></tr>
<tr><td colspan="2"><center><input type="submit" value="Reseteaza parola"></center></td></tr>
</table>
</form>
<?
error_reporting (E_ALL ^ E_NOTICE);
function clean($str) {
		$str = @trim($str);
		if(get_magic_quotes_gpc()) {
			$str = stripslashes($str);
		}
		return mysql_real_escape_string($str);
	}
include('config.php');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
$email=clean($_POST['email']);
$sqlemail=mysql_fetch_array(mysql_query("select email from elev where email='".$email."'"));
if ($email==$sqlemail['email'] and $email!='') {
function createRandomPassword() {
$chars = "abcdefghijkmnopqrstuvwxyz023456789!@#$%^&*()_+";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;

}
    return $pass;
}

$newpass=createRandomPassword();
$update=mysql_query("UPDATE elev set parola='".md5($newpass)."' where email='".$email."'");
mail($email,'Subject: Resetare parola',"Parola noua: $newpass",'From: Catalog online');
header('location: index.php');
}

?>
</body>
</html>